#!/bin/sh

prefix=circle
equation='100*x*x*x+y*y+20*x*y'

 if [ -z "$bamg" ] ;then bamg=../../bamg; fi

#   for compatibility  pb in awk if  LANG=French 
LANG=C
export LANG

##   initialisation 
  i=0 
  MESH=${prefix}_$i.mesh
  GEOM=${prefix}_g.mesh
  echo    ${bamg} -g $GEOM   -o $MESH -oam_fmt $MESH.am_fmt
  ${bamg} -g $GEOM   -o $MESH -oam_fmt $MESH.am_fmt
##  do a simple loop of adpation i1 = i-1   
  for i in 1 2 3  ; do

	 BACK=${MESH}
 	 MESH=${prefix}_$i.mesh
 	 SOL=${BACK}.bb

  #  generation of the solution file with awk 
	 awk '   BEGIN {k=0}
  	         k>0  {k--; x=$1;y=$2;print '$equation'}
	        (k==-1)  {k=$1; print 2,1,k,2;}
                $1=="Vertices"  {k=-1;}
              ' $BACK > $SOL
  # generation of the adapted mesh 
  echo  ${bamg} -AbsError -v 8 -b $BACK -Mbb $SOL -err 0.005 -hmin 0.00001   -NbSmooth 3 -NbJacobi 3 -o $MESH	-oam_fmt $MESH.am_fmt
	${bamg} -AbsError -v 8 -b $BACK -Mbb $SOL -err 0.005 -hmin 0.00001   -NbSmooth 3 -NbJacobi 3 -o $MESH	-oam_fmt $MESH.am_fmt
	echo "to see the result enter :  ../../drawbdmesh $MESH"
   done 
